<template>
	<view class="container">
		<image src="../../static/login_icons/logo.png" class="logo"></image>
		<view class="login-selected" v-show="isShow === 1">
			<button type="default" class="mini-logo" @click="guestInto()">
				<image src="../../static/login_icons/guest.png"></image>
				<text style="color:#C2000A ;">游客进入</text>
			</button>
			<button type="default" class="mini-logo" style="
background: linear-gradient(90deg, #E62129 0%, #BA000A 100%);" @click="memberInto()">
				<image src="../../static/login_icons/member.png"></image>
				<text>会员进入</text>
			</button>
		</view>
		<uni-popup ref="popup" type="share" isMaskClick="false">
			<uni-popup-share title="隐私权限声明" :content="statementData" @changLoginShow="changeLoginShow()">
			</uni-popup-share>
		</uni-popup>
	</view>
</template>

<script>
	import store from '@/store/store.js'
	export default {
		data() {
			return {
				isShow: 0,
				statementData: "本人个信息保护指引将通过《用户协议》与《隐私政策》帮助你了解我们如何收集、处理个人信息。你可随时在“设置-隐私”中关闭个性化推荐权限，仅使用App基本功能。本人个信息保护指引将通过《用户协议》与《隐私政策》帮助你了解我们如何收集、处理个人信息。你可随时在“设置-隐私”中关闭个性化推荐权限，仅使用App基本功能。",
				checkout: false,

			};
		},
		onLoad() {
			this.setStatementData();
			this.getCode();
		},
		onReady() {
			this.$refs.popup.open();
		},
		methods: {
			getCode() {
				uni.login({
					onlyAuthorize: true,
					success(e) {
						console.log('获取的code：' + e.code);
						store.dispatch('user/setCODE', e.code)
					}
				})
			},
			//初始化声明协议
			async setStatementData() {
				const {
					data: res
				} = await uni.$http.get(uni.$http.baseURL + '/user/userAgreement', {
					agreeId: 1
				})
				// console.log(res.body)
				// this.statementData=res.body
			},
			goto(url) {
				// this.userIsExist()
				uni.navigateTo({
					url: url
				})
			},
			changeLoginShow() {
				this.isShow = 1
			},
			async tranferOpenId(code) {
				const {
					data: res
				} = await uni.$http.get(uni.$http.baseURL + '/user/getOpenId', {
					code: code
				})
				store.dispatch('user/setOpenID', res.body)
				const {
					data: res2
				} = await uni.$http.get(uni.$http.baseURL + '/user/isExist', {
					wxId: res.body
				})
				if (res2.body.exist) {
					// if (this.checkout) {
						this.goto('/pages/login_form/login_form')
					// } else {
					// 	uni.switchTab({
					// 		url:'/pages/home/home'
					// 	})
					// }
				} else {
					if (this.checkout) {
						this.goto('/pages/member_register/member_register')
					} else {
						this.goto('/pages/guest_register/guest_register')

					}
				}
				console.log(res2.body.exist)
			},
			guestInto() {
				this.getCode();
				this.checkout = false
				const code = store.getters['user/code']
				// console.log('设置的code：' + code)
				this.tranferOpenId(code)
			},
			memberInto() {
				this.getCode();
				this.checkout = true
				const code = store.getters['user/code']
				this.tranferOpenId(code)

			}
		}
	}
</script>

<style lang="scss">
	.container {
		display: flex;
		flex-direction: column;

		.logo {
			height: 211rpx;
			width: 175rpx;
			margin-top: 302rpx;
			margin-left: 287rpx;
		}

		.login-selected {
			margin-top: 120rpx;
			margin-left: 95rpx;
			margin-right: 95rpx;
		}

		.mini-logo {
			display: flex;
			width: 100%;
			margin-bottom: 40rpx;
			align-items: center;
			flex-direction: inherit;
			justify-content: center;

			border-radius: 44rpx;
			box-shadow: 0rpx 5rpx 15rpx 0rpx rgba(0, 0, 0, 0.05);

			image {
				height: 27rpx;
				width: 27rpx;
				margin-right: 17rpx;
			}

			text {
				font-weight: bold;
				font-family: PingFang SC;
				font-size: 30rpx;
			}
		}
	}

	.state-confirm {
		// border-top-left-radius: 11rpx;
		// border-top-right-radius: 11rpx;
		width: 750rpx;
		height: 600rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 7rpx 18rpx 2rpx rgba(132, 132, 132, 0.2);
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		display: flexbox;
		flex-direction: column;

		.state-confirm-content {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-family: PingFang SC;

			.state-confirm-title {
				margin: 40rpx 280rpx 0 280rpx;
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
			}

			.statement {
				margin: 29rpx 44rpx 0 44rpx;
			}
		}

		.state-confirm-button-box {
			display: flex;
			flex-direction: row;
			margin-bottom: 60rpx;
			justify-content: space-around;
		}
	}



	.uni-share-button {
		flex: 1;
		border-radius: 50px;
		color: #666;
		font-size: 16px;
	}

	.uni-share-button::after {
		border-radius: 50px;
	}
</style>
